using System;
using System.Drawing;
using System.Windows.Forms;

namespace WindowsFormsDataBaice
{
    public class MainForm : Form
    {
        private Panel pnlHeader;
        private Panel pnlNavigation;
        private Panel pnlContent;
        private Panel pnlFooter;
        private Label lblSystemTitle;
        private Label lblCurrentUser;
        private Label lblSystemIcon;
        private Label lblDateTime;
        private Label lblTimeDisplay; // 用户信息区域的时间显示
        private Label lblDateDisplay; // 用户信息区域的日期显示
        private Button[] moduleButtons;
        private string[] moduleNames = {
            "系统管理", "门诊医生", "门诊管理", "门诊收费", 
            "住院管理", "药房管理", "药库管理", "财务管理"
        };

        // 登录信息
        private int currentUserId;
        private string currentUsername;
        private string currentRealName;
        private string[] currentRoleNames;
        private Timer timeTimer;

        public MainForm()
        {
            InitializeComponent();
            SetupEventHandlers();
            SetupTimeTimer();
        }

        // 带登录信息的构造函数
        public MainForm(int userId, string username, string realName, string[] roleNames)
        {
            this.currentUserId = userId;
            this.currentUsername = username;
            this.currentRealName = realName;
            this.currentRoleNames = roleNames;
            
            InitializeComponent();
            SetupEventHandlers();
            SetupTimeTimer();
            UpdateUserInfo();
        }

        private void InitializeComponent()
        {
            this.Text = "医疗信息管理系统";
            this.Size = new Size(1200, 800);
            this.StartPosition = FormStartPosition.CenterScreen;
            this.BackColor = UIStyleManager.BackgroundColor;
            this.FormBorderStyle = FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;

            // 顶部标题栏
            pnlHeader = new Panel
            {
                Dock = DockStyle.Top,
                Height = 70,
                BackColor = UIStyleManager.PrimaryColor
            };

            // 系统图标
            lblSystemIcon = new Label
            {
                Text = IconManager.Icons.Hospital,
                Font = new Font("Segoe UI Emoji", 24),
                ForeColor = Color.White,
                Location = new Point(20, 15),
                AutoSize = true
            };

            // 系统标题
            lblSystemTitle = new Label
            {
                Text = "医疗信息管理系统",
                ForeColor = Color.White,
                Font = UIStyleManager.TitleFont,
                Location = new Point(60, 15),
                AutoSize = true
            };

            // 当前用户信息
            lblCurrentUser = new Label
            {
                Text = $"{IconManager.Icons.User} 当前用户: 管理员",
                ForeColor = Color.White,
                Font = UIStyleManager.BodyFont,
                Location = new Point(750, 15),
                AutoSize = true
            };

            // 用户信息区域的时间显示 - 上面时分秒
            lblTimeDisplay = new Label
            {
                Text = $"{IconManager.Icons.Clock} {DateTime.Now.ToString("HH:mm:ss")}",
                ForeColor = Color.White,
                Font = new Font("微软雅黑", 12, FontStyle.Bold),
                Location = new Point(950, 15),
                AutoSize = true
            };

            // 用户信息区域的日期显示 - 下面年月日
            lblDateDisplay = new Label
            {
                Text = DateTime.Now.ToString("yyyy年MM月dd日"),
                ForeColor = Color.White,
                Font = new Font("微软雅黑", 10, FontStyle.Regular),
                Location = new Point(970, 35),
                AutoSize = true
            };

            pnlHeader.Controls.Add(lblSystemIcon);
            pnlHeader.Controls.Add(lblSystemTitle);
            pnlHeader.Controls.Add(lblCurrentUser);
            pnlHeader.Controls.Add(lblTimeDisplay);
            pnlHeader.Controls.Add(lblDateDisplay);

            // 导航栏
            pnlNavigation = new Panel
            {
                Dock = DockStyle.Top,
                Height = 60,
                BackColor = UIStyleManager.PrimaryDarkColor
            };

            // 创建模块按钮
            moduleButtons = new Button[moduleNames.Length];
            int buttonWidth = 130;
            int buttonHeight = 40;
            int startX = 20;
            int buttonSpacing = 15;

            for (int i = 0; i < moduleNames.Length; i++)
            {
                string icon = IconManager.GetModuleIcon(moduleNames[i]);
                moduleButtons[i] = IconManager.CreateSmallIconButton(moduleNames[i], icon, buttonWidth, buttonHeight);
                moduleButtons[i].Location = new Point(startX + i * (buttonWidth + buttonSpacing), 10);
                moduleButtons[i].Tag = i; // 用于标识按钮
                pnlNavigation.Controls.Add(moduleButtons[i]);
            }

            // 主内容区域
            pnlContent = new Panel
            {
                Dock = DockStyle.Fill,
                BackColor = UIStyleManager.BackgroundColor,
                BorderStyle = BorderStyle.None
            };

            // 欢迎信息面板
            Panel welcomePanel = UIStyleManager.CreateCardPanel("", 600, 300);
            welcomePanel.Location = new Point(300, 150);
            welcomePanel.BorderStyle = BorderStyle.None;

            // 欢迎图标
            Label lblWelcomeIcon = new Label
            {
                Text = IconManager.Icons.Hospital,
                Font = new Font("Segoe UI Emoji", 48),
                ForeColor = UIStyleManager.PrimaryColor,
                AutoSize = true,
                Location = new Point(250, 30)
            };

            // 欢迎标题
            Label lblWelcome = new Label
            {
                Text = "欢迎使用医疗信息管理系统",
                Font = UIStyleManager.TitleFont,
                ForeColor = UIStyleManager.PrimaryColor,
                AutoSize = true,
                Location = new Point(150, 100)
            };

            // 欢迎副标题
            Label lblSubTitle = new Label
            {
                Text = "请选择上方模块开始使用",
                Font = UIStyleManager.SubtitleFont,
                ForeColor = UIStyleManager.TextSecondaryColor,
                AutoSize = true,
                Location = new Point(200, 150)
            };

            // 系统信息
            Label lblSystemInfo = new Label
            {
                Text = $"{IconManager.Icons.Info} 系统版本: v1.0.0 | 最后更新: {DateTime.Now:yyyy-MM-dd}",
                Font = UIStyleManager.SmallFont,
                ForeColor = UIStyleManager.TextSecondaryColor,
                AutoSize = true,
                Location = new Point(180, 200)
            };

            welcomePanel.Controls.Add(lblWelcomeIcon);
            welcomePanel.Controls.Add(lblWelcome);
            welcomePanel.Controls.Add(lblSubTitle);
            welcomePanel.Controls.Add(lblSystemInfo);
            pnlContent.Controls.Add(welcomePanel);

            // 底部状态栏
            pnlFooter = new Panel
            {
                Dock = DockStyle.Bottom,
                Height = 35,
                BackColor = Color.FromArgb(44, 62, 80) // 深蓝色背景
            };

            Label lblStatus = new Label
            {
                Text = $"{IconManager.Icons.Check} 系统就绪",
                ForeColor = Color.FromArgb(52, 152, 219), // 青色文字
                Font = UIStyleManager.SmallFont,
                Location = new Point(10, 10),
                AutoSize = true
            };

            lblDateTime = new Label
            {
                Text = $"{IconManager.Icons.Clock} {DateTime.Now:yyyy-MM-dd HH:mm:ss}",
                ForeColor = Color.FromArgb(52, 152, 219), // 青色文字
                Font = UIStyleManager.SmallFont,
                Location = new Point(1000, 10),
                AutoSize = true
            };

            pnlFooter.Controls.Add(lblStatus);
            pnlFooter.Controls.Add(lblDateTime);

            // 添加面板到窗体
            this.Controls.Add(pnlHeader);
            this.Controls.Add(pnlNavigation);
            this.Controls.Add(pnlContent);
            this.Controls.Add(pnlFooter);
        }

        private void SetupEventHandlers()
        {
            // 为每个模块按钮添加点击事件
            for (int i = 0; i < moduleButtons.Length; i++)
            {
                int moduleIndex = i; // 捕获循环变量
                moduleButtons[i].Click += (s, e) => ModuleButton_Click(s, e, moduleIndex);
            }
        }

        private void ModuleButton_Click(object sender, EventArgs e, int moduleIndex)
        {
            // 重置所有按钮样式
            foreach (var btn in moduleButtons)
            {
                UIStyleManager.ApplyButtonStyle(btn, ButtonStyle.Primary);
            }

            // 设置当前选中按钮样式
            Button clickedButton = sender as Button;
            UIStyleManager.ApplyButtonStyle(clickedButton, ButtonStyle.Secondary);

            // 清空主内容区域
            pnlContent.Controls.Clear();

            // 根据模块索引显示对应功能
            switch (moduleIndex)
            {
                case 0: // 系统管理
                    ShowSystemManagementPanel();
                    break;
                case 1: // 门诊医生
                    ShowDoctorWorkstationPanel();
                    break;
                case 2: // 门诊管理
                    ShowOutpatientManagementPanel();
                    break;
                case 3: // 门诊收费
                    ShowChargePanel();
                    break;
                case 4: // 住院管理
                    MessageBox.Show("住院管理模块开发中...", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    break;
                case 5: // 药房管理
                    MessageBox.Show("药房管理模块开发中...", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    break;
                case 6: // 药库管理
                    MessageBox.Show("药库管理模块开发中...", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    break;
                case 7: // 财务管理
                    MessageBox.Show("财务管理模块开发中...", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    break;
            }
        }

        private void OpenFormInPanel(Form form)
        {
            // 清空主内容区域
            pnlContent.Controls.Clear();

            // 设置窗体属性
            form.TopLevel = false;
            form.FormBorderStyle = FormBorderStyle.None;
            form.Dock = DockStyle.Fill;

            // 添加到主内容区域
            pnlContent.Controls.Add(form);
            form.Show();
        }

        private void SetupTimeTimer()
        {
            timeTimer = new Timer();
            timeTimer.Interval = 1000; // 每秒更新一次
            timeTimer.Tick += TimeTimer_Tick;
            timeTimer.Start();
        }

        private void TimeTimer_Tick(object sender, EventArgs e)
        {
            lblDateTime.Text = $"{IconManager.Icons.Clock} {DateTime.Now:yyyy-MM-dd HH:mm:ss}";
            lblTimeDisplay.Text = $"{IconManager.Icons.Clock} {DateTime.Now.ToString("HH:mm:ss")}";
            lblDateDisplay.Text = DateTime.Now.ToString("yyyy年MM月dd日");
        }

        private void UpdateUserInfo()
        {
            string roleInfo = currentRoleNames != null && currentRoleNames.Length > 0 
                ? string.Join(", ", currentRoleNames) 
                : "用户";
            
            lblCurrentUser.Text = $"{IconManager.Icons.User} 当前用户: {currentRealName} ({currentUsername})";
        }

        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);
            if (timeTimer != null)
            {
                timeTimer.Stop();
                timeTimer.Dispose();
            }
        }

        private void ShowSystemManagementPanel()
        {
            // 创建系统管理面板
            Panel systemPanel = new Panel
            {
                Dock = DockStyle.Fill,
                BackColor = Color.FromArgb(248, 249, 250),
                Padding = new Padding(15)
            };

            // 创建功能图标网格
            TableLayoutPanel iconGrid = new TableLayoutPanel
            {
                Dock = DockStyle.Fill,
                ColumnCount = 4,
                RowCount = 2,
                ColumnStyles = {
                    new ColumnStyle(SizeType.Percent, 25),
                    new ColumnStyle(SizeType.Percent, 25),
                    new ColumnStyle(SizeType.Percent, 25),
                    new ColumnStyle(SizeType.Percent, 25)
                },
                RowStyles = {
                    new RowStyle(SizeType.Percent, 50),
                    new RowStyle(SizeType.Percent, 50)
                },
                Padding = new Padding(8, 8, 8, 8)
            };

            // 创建功能图标
            CreateFunctionIcon(iconGrid, "挂号单设置", "📋", 0, 0, (s, e) => new RegisterTemplateForm().ShowDialog());
            CreateFunctionIcon(iconGrid, "门诊单设置", "📄", 1, 0, (s, e) => new OutpatientForm().ShowDialog());
            CreateFunctionIcon(iconGrid, "住院单设置", "🏥", 2, 0, (s, e) => new InpatientForm().ShowDialog());
            CreateFunctionIcon(iconGrid, "数据库备份", "💾", 3, 0, (s, e) => MessageBox.Show("数据库备份功能", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information));
            CreateFunctionIcon(iconGrid, "科室管理", "🏢", 0, 1, (s, e) => ShowDepartmentManagement());
            CreateFunctionIcon(iconGrid, "权限管理", "🔐", 1, 1, (s, e) => new PermissionManagementForm().ShowDialog());
            CreateFunctionIcon(iconGrid, "员工添加", "👤", 2, 1, (s, e) => new UserManagementForm().ShowDialog());
            CreateFunctionIcon(iconGrid, "数据恢复", "🔄", 3, 1, (s, e) => MessageBox.Show("数据恢复功能", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information));

            systemPanel.Controls.Add(iconGrid);
            pnlContent.Controls.Add(systemPanel);
        }

        private void CreateFunctionIcon(TableLayoutPanel parent, string title, string icon, int column, int row, EventHandler clickHandler)
        {
            // 创建图标容器
            Panel iconPanel = new Panel
            {
                Dock = DockStyle.Fill,
                BackColor = Color.White,
                BorderStyle = BorderStyle.FixedSingle,
                Margin = new Padding(3),
                Padding = new Padding(5)
            };

            // 创建图标标签
            Label iconLabel = new Label
            {
                Text = icon,
                Font = new Font("Segoe UI Emoji", 40),
                ForeColor = Color.FromArgb(52, 152, 219),
                TextAlign = ContentAlignment.MiddleCenter,
                Dock = DockStyle.Fill,
                Height = 0
            };

            // 创建标题标签
            Label titleLabel = new Label
            {
                Text = title,
                Font = new Font("微软雅黑", 9, FontStyle.Bold),
                ForeColor = Color.FromArgb(52, 73, 94),
                TextAlign = ContentAlignment.MiddleCenter,
                Dock = DockStyle.Bottom,
                Height = 25
            };

            // 添加控件到面板
            iconPanel.Controls.Add(iconLabel);
            iconPanel.Controls.Add(titleLabel);

            // 添加点击事件
            iconPanel.Click += clickHandler;
            iconLabel.Click += clickHandler;
            titleLabel.Click += clickHandler;

            // 添加鼠标悬停效果
            iconPanel.MouseEnter += (s, e) => {
                iconPanel.BackColor = Color.FromArgb(240, 240, 240);
                iconPanel.Cursor = Cursors.Hand;
            };
            iconPanel.MouseLeave += (s, e) => {
                iconPanel.BackColor = Color.White;
                iconPanel.Cursor = Cursors.Default;
            };

            // 添加到网格
            parent.Controls.Add(iconPanel, column, row);
        }

        private void ShowRegistrationSlipDesign()
        {
            // 创建挂号单设计窗体
            Form registrationForm = new Form
            {
                Text = "挂号单设计",
                Size = new Size(800, 600),
                StartPosition = FormStartPosition.CenterParent,
                BackColor = Color.White
            };

            // 创建主面板
            Panel mainPanel = new Panel
            {
                Dock = DockStyle.Fill,
                Padding = new Padding(20)
            };

            // 顶部控制区域
            Panel topPanel = new Panel
            {
                Dock = DockStyle.Top,
                Height = 60,
                BackColor = Color.White
            };

            Label lblTitle = new Label
            {
                Text = "标题文本:",
                Location = new Point(20, 20),
                AutoSize = true
            };

            TextBox txtTitle = new TextBox
            {
                Location = new Point(100, 20),
                Size = new Size(150, 25),
                Text = "挂号单"
            };

            Button btnAddItem = new Button
            {
                Text = "添加项目",
                Location = new Point(270, 20),
                Size = new Size(80, 25),
                BackColor = UIStyleManager.PrimaryColor,
                ForeColor = Color.White,
                FlatStyle = FlatStyle.Flat
            };

            Label lblPreview = new Label
            {
                Text = "预览区",
                Location = new Point(370, 20),
                AutoSize = true
            };

            Button btnPrint = new Button
            {
                Text = "打印",
                Location = new Point(450, 20),
                Size = new Size(60, 25),
                BackColor = Color.FromArgb(52, 152, 219),
                ForeColor = Color.White,
                FlatStyle = FlatStyle.Flat
            };

            topPanel.Controls.AddRange(new Control[] { lblTitle, txtTitle, btnAddItem, lblPreview, btnPrint });

            // 左侧设计区域
            Panel leftPanel = new Panel
            {
                Dock = DockStyle.Left,
                Width = 400,
                BackColor = Color.White,
                BorderStyle = BorderStyle.FixedSingle
            };

            Label lblDesignArea = new Label
            {
                Text = "设计区",
                Location = new Point(10, 10),
                AutoSize = true,
                Font = new Font("微软雅黑", 12, FontStyle.Bold)
            };

            Panel designArea = new Panel
            {
                Location = new Point(10, 40),
                Size = new Size(380, 400),
                BackColor = Color.White,
                BorderStyle = BorderStyle.FixedSingle
            };

            leftPanel.Controls.Add(lblDesignArea);
            leftPanel.Controls.Add(designArea);

            // 右侧打印项目区域
            Panel rightPanel = new Panel
            {
                Dock = DockStyle.Fill,
                BackColor = Color.White,
                Padding = new Padding(10)
            };

            Label lblPrintItems = new Label
            {
                Text = "打印项目",
                Location = new Point(10, 10),
                AutoSize = true,
                Font = new Font("微软雅黑", 12, FontStyle.Bold)
            };

            CheckedListBox lstPrintItems = new CheckedListBox
            {
                Location = new Point(10, 40),
                Size = new Size(200, 300),
                Font = new Font("微软雅黑", 10)
            };

            // 添加打印项目
            lstPrintItems.Items.AddRange(new object[] {
                "编号", "科室", "医师", "处方药", "病床号", "问诊时间", 
                "入院时间", "出院时间", "消费明细", "收银员", "消费金额"
            });

            // 设置医师为选中状态
            lstPrintItems.SetItemChecked(2, true);

            rightPanel.Controls.Add(lblPrintItems);
            rightPanel.Controls.Add(lstPrintItems);

            // 底部按钮区域
            Panel bottomPanel = new Panel
            {
                Dock = DockStyle.Bottom,
                Height = 50,
                BackColor = Color.White
            };

            Button btnSave = new Button
            {
                Text = "保存",
                Location = new Point(20, 10),
                Size = new Size(80, 30),
                BackColor = Color.FromArgb(46, 204, 113),
                ForeColor = Color.White,
                FlatStyle = FlatStyle.Flat
            };

            Button btnClear = new Button
            {
                Text = "清空",
                Location = new Point(120, 10),
                Size = new Size(80, 30),
                BackColor = Color.FromArgb(149, 165, 166),
                ForeColor = Color.White,
                FlatStyle = FlatStyle.Flat
            };

            Button btnPreview = new Button
            {
                Text = "预览",
                Location = new Point(220, 10),
                Size = new Size(80, 30),
                BackColor = Color.FromArgb(155, 89, 182),
                ForeColor = Color.White,
                FlatStyle = FlatStyle.Flat
            };

            bottomPanel.Controls.AddRange(new Control[] { btnSave, btnClear, btnPreview });

            // 添加所有面板到主面板
            mainPanel.Controls.Add(rightPanel);
            mainPanel.Controls.Add(leftPanel);
            mainPanel.Controls.Add(topPanel);
            mainPanel.Controls.Add(bottomPanel);

            registrationForm.Controls.Add(mainPanel);
            registrationForm.ShowDialog();
        }

        private void ShowDepartmentManagement()
        {
            // 使用真正的科室管理窗体
            DepartmentManagementForm departmentForm = new DepartmentManagementForm();
            departmentForm.ShowDialog();
        }



        private void ShowDepartmentEditForm()
        {
            // 使用真正的科室管理窗体
            DepartmentManagementForm departmentForm = new DepartmentManagementForm();
            departmentForm.ShowDialog();
        }



        private void ShowOutpatientDoctorPanel()
        {
            // 创建门诊医生面板
            Panel doctorPanel = new Panel
            {
                Dock = DockStyle.Fill,
                BackColor = Color.White,
                Padding = new Padding(20)
            };

            // 创建功能图标网格
            TableLayoutPanel iconGrid = new TableLayoutPanel
            {
                Dock = DockStyle.Fill,
                ColumnCount = 3,
                RowCount = 2,
                ColumnStyles = {
                    new ColumnStyle(SizeType.Percent, 33.33f),
                    new ColumnStyle(SizeType.Percent, 33.33f),
                    new ColumnStyle(SizeType.Percent, 33.33f)
                },
                RowStyles = {
                    new RowStyle(SizeType.Percent, 50),
                    new RowStyle(SizeType.Percent, 50)
                }
            };

            // 创建门诊医生功能图标
            CreateFunctionIcon(iconGrid, "医生工作站", "👨‍⚕️", 0, 0, (s, e) => MessageBox.Show("医生工作站功能", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information));
            CreateFunctionIcon(iconGrid, "医生排班", "📅", 1, 0, (s, e) => MessageBox.Show("医生排班功能", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information));
            CreateFunctionIcon(iconGrid, "医生信息", "📋", 2, 0, (s, e) => MessageBox.Show("医生信息管理", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information));
            CreateFunctionIcon(iconGrid, "处方管理", "💊", 0, 1, (s, e) => MessageBox.Show("处方管理功能", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information));
            CreateFunctionIcon(iconGrid, "病历查看", "📖", 1, 1, (s, e) => MessageBox.Show("病历查看功能", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information));
            CreateFunctionIcon(iconGrid, "诊断记录", "🔍", 2, 1, (s, e) => MessageBox.Show("诊断记录功能", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information));

            doctorPanel.Controls.Add(iconGrid);
            pnlContent.Controls.Add(doctorPanel);
        }



        private void ShowOutpatientBillingPanel()
        {
            // 创建门诊收费面板
            Panel billingPanel = new Panel
            {
                Dock = DockStyle.Fill,
                BackColor = Color.White,
                Padding = new Padding(20)
            };

            // 创建功能图标网格
            TableLayoutPanel iconGrid = new TableLayoutPanel
            {
                Dock = DockStyle.Fill,
                ColumnCount = 3,
                RowCount = 2,
                ColumnStyles = {
                    new ColumnStyle(SizeType.Percent, 33.33f),
                    new ColumnStyle(SizeType.Percent, 33.33f),
                    new ColumnStyle(SizeType.Percent, 33.33f)
                },
                RowStyles = {
                    new RowStyle(SizeType.Percent, 50),
                    new RowStyle(SizeType.Percent, 50)
                }
            };

            // 创建门诊收费功能图标
            CreateFunctionIcon(iconGrid, "收费结算", "💰", 0, 0, (s, e) => ShowBillingSettlement());
            CreateFunctionIcon(iconGrid, "退费处理", "💸", 1, 0, (s, e) => MessageBox.Show("退费处理功能", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information));
            CreateFunctionIcon(iconGrid, "费用查询", "🔍", 2, 0, (s, e) => MessageBox.Show("费用查询功能", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information));
            CreateFunctionIcon(iconGrid, "发票打印", "🖨️", 0, 1, (s, e) => MessageBox.Show("发票打印功能", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information));
            CreateFunctionIcon(iconGrid, "收费统计", "📊", 1, 1, (s, e) => MessageBox.Show("收费统计功能", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information));
            CreateFunctionIcon(iconGrid, "价格设置", "⚙️", 2, 1, (s, e) => MessageBox.Show("价格设置功能", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information));

            billingPanel.Controls.Add(iconGrid);
            pnlContent.Controls.Add(billingPanel);
        }

        private void ShowRegistrationManagement()
        {
            // 创建挂号管理窗体
            Form registrationForm = new Form
            {
                Text = "挂号管理",
                Size = new Size(1000, 700),
                StartPosition = FormStartPosition.CenterParent,
                BackColor = Color.White
            };

            // 创建主面板
            Panel mainPanel = new Panel
            {
                Dock = DockStyle.Fill,
                Padding = new Padding(20)
            };

            // 顶部工具栏
            Panel toolbarPanel = new Panel
            {
                Dock = DockStyle.Top,
                Height = 60,
                BackColor = Color.White
            };

            Button btnNewRegistration = new Button
            {
                Text = "新建挂号",
                Location = new Point(20, 15),
                Size = new Size(100, 30),
                BackColor = Color.FromArgb(46, 204, 113),
                ForeColor = Color.White,
                FlatStyle = FlatStyle.Flat
            };

            Button btnSearch = new Button
            {
                Text = "查询",
                Location = new Point(140, 15),
                Size = new Size(80, 30),
                BackColor = Color.FromArgb(52, 152, 219),
                ForeColor = Color.White,
                FlatStyle = FlatStyle.Flat
            };

            TextBox txtSearch = new TextBox
            {
                Location = new Point(240, 20),
                Size = new Size(200, 25)
            };

            toolbarPanel.Controls.AddRange(new Control[] { btnNewRegistration, btnSearch, txtSearch });

            // 数据网格
            DataGridView dgvRegistrations = new DataGridView
            {
                Dock = DockStyle.Fill,
                AllowUserToAddRows = false,
                ReadOnly = true,
                AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
                BackgroundColor = Color.White
            };

            // 设置列
            dgvRegistrations.Columns.Add("ID", "挂号ID");
            dgvRegistrations.Columns.Add("PatientName", "患者姓名");
            dgvRegistrations.Columns.Add("Department", "科室");
            dgvRegistrations.Columns.Add("Doctor", "医生");
            dgvRegistrations.Columns.Add("RegistrationTime", "挂号时间");
            dgvRegistrations.Columns.Add("Status", "状态");

            // 添加示例数据
            dgvRegistrations.Rows.Add("R001", "张三", "内科", "李医生", "2025-07-30 09:00", "已挂号");
            dgvRegistrations.Rows.Add("R002", "李四", "外科", "王医生", "2025-07-30 09:30", "已挂号");
            dgvRegistrations.Rows.Add("R003", "王五", "儿科", "赵医生", "2025-07-30 10:00", "已挂号");

            mainPanel.Controls.Add(dgvRegistrations);
            mainPanel.Controls.Add(toolbarPanel);

            registrationForm.Controls.Add(mainPanel);
            registrationForm.ShowDialog();
        }

        private void ShowBillingSettlement()
        {
            // 创建收费结算窗体
            Form billingForm = new Form
            {
                Text = "收费结算",
                Size = new Size(1000, 700),
                StartPosition = FormStartPosition.CenterParent,
                BackColor = Color.White
            };

            // 创建主面板
            Panel mainPanel = new Panel
            {
                Dock = DockStyle.Fill,
                Padding = new Padding(20)
            };

            // 左侧患者信息
            Panel leftPanel = new Panel
            {
                Dock = DockStyle.Left,
                Width = 300,
                BackColor = Color.White,
                BorderStyle = BorderStyle.FixedSingle
            };

            Label lblPatientInfo = new Label
            {
                Text = "患者信息",
                Location = new Point(10, 10),
                AutoSize = true,
                Font = new Font("微软雅黑", 12, FontStyle.Bold)
            };

            Label lblPatientName = new Label
            {
                Text = "患者姓名: 张三",
                Location = new Point(10, 40),
                AutoSize = true
            };

            Label lblPatientID = new Label
            {
                Text = "患者ID: P001",
                Location = new Point(10, 70),
                AutoSize = true
            };

            Label lblDepartment = new Label
            {
                Text = "科室: 内科",
                Location = new Point(10, 100),
                AutoSize = true
            };

            Label lblDoctor = new Label
            {
                Text = "医生: 李医生",
                Location = new Point(10, 130),
                AutoSize = true
            };

            leftPanel.Controls.AddRange(new Control[] { lblPatientInfo, lblPatientName, lblPatientID, lblDepartment, lblDoctor });

            // 右侧费用明细
            Panel rightPanel = new Panel
            {
                Dock = DockStyle.Fill,
                BackColor = Color.White,
                Padding = new Padding(20)
            };

            Label lblFeeDetails = new Label
            {
                Text = "费用明细",
                Location = new Point(10, 10),
                AutoSize = true,
                Font = new Font("微软雅黑", 12, FontStyle.Bold)
            };

            DataGridView dgvFees = new DataGridView
            {
                Location = new Point(10, 40),
                Size = new Size(400, 300),
                AllowUserToAddRows = false,
                ReadOnly = true,
                AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
                BackgroundColor = Color.White
            };

            // 设置费用明细列
            dgvFees.Columns.Add("Item", "项目");
            dgvFees.Columns.Add("UnitPrice", "单价");
            dgvFees.Columns.Add("Quantity", "数量");
            dgvFees.Columns.Add("Amount", "金额");

            // 添加费用明细
            dgvFees.Rows.Add("挂号费", "10.00", "1", "10.00");
            dgvFees.Rows.Add("诊疗费", "50.00", "1", "50.00");
            dgvFees.Rows.Add("检查费", "100.00", "1", "100.00");
            dgvFees.Rows.Add("药品费", "80.00", "1", "80.00");

            // 底部结算区域
            Panel bottomPanel = new Panel
            {
                Dock = DockStyle.Bottom,
                Height = 100,
                BackColor = Color.White,
                BorderStyle = BorderStyle.FixedSingle
            };

            Label lblTotal = new Label
            {
                Text = "总计: ¥240.00",
                Location = new Point(10, 20),
                AutoSize = true,
                Font = new Font("微软雅黑", 14, FontStyle.Bold)
            };

            Button btnSettle = new Button
            {
                Text = "结算",
                Location = new Point(200, 15),
                Size = new Size(100, 40),
                BackColor = Color.FromArgb(46, 204, 113),
                ForeColor = Color.White,
                FlatStyle = FlatStyle.Flat,
                Font = new Font("微软雅黑", 12)
            };

            Button btnCancel = new Button
            {
                Text = "取消",
                Location = new Point(320, 15),
                Size = new Size(100, 40),
                BackColor = Color.FromArgb(149, 165, 166),
                ForeColor = Color.White,
                FlatStyle = FlatStyle.Flat,
                Font = new Font("微软雅黑", 12)
            };

            bottomPanel.Controls.AddRange(new Control[] { lblTotal, btnSettle, btnCancel });

            rightPanel.Controls.Add(lblFeeDetails);
            rightPanel.Controls.Add(dgvFees);
            rightPanel.Controls.Add(bottomPanel);

            mainPanel.Controls.Add(rightPanel);
            mainPanel.Controls.Add(leftPanel);

            billingForm.Controls.Add(mainPanel);
            billingForm.ShowDialog();
        }

        private void ShowDoctorWorkstationPanel()
        {
            // 打开医生工作站窗体
            DoctorWorkstationForm doctorWorkstation = new DoctorWorkstationForm(currentUserId, currentUsername);
            doctorWorkstation.ShowDialog();
        }

        private void ShowChargePanel()
        {
            // 打开门诊收费窗体
            ChargeForm chargeForm = new ChargeForm(currentUserId, currentUsername);
            chargeForm.ShowDialog();
        }

        private void ShowOutpatientManagementPanel()
        {
            // 创建门诊管理面板
            Panel outpatientPanel = new Panel
            {
                Dock = DockStyle.Fill,
                BackColor = Color.FromArgb(248, 249, 250),
                Padding = new Padding(20)
            };

            // 添加标题
            Label lblTitle = new Label
            {
                Text = $"{IconManager.Icons.Hospital} 门诊管理",
                Font = UIStyleManager.TitleFont,
                ForeColor = UIStyleManager.PrimaryColor,
                Location = new Point(30, 30),
                AutoSize = true
            };

            // 创建功能按钮容器
            Panel buttonContainer = new Panel
            {
                Location = new Point(50, 100),
                Size = new Size(800, 400),
                BackColor = Color.Transparent
            };

            // 病人挂号按钮
            Button btnRegistration = new Button
            {
                Text = $"{IconManager.Icons.User}\r\n病人挂号",
                Size = new Size(200, 120),
                Location = new Point(100, 50),
                BackColor = Color.FromArgb(52, 152, 219),
                ForeColor = Color.White,
                Font = new Font("微软雅黑", 14, FontStyle.Bold),
                FlatStyle = FlatStyle.Flat,
                Cursor = Cursors.Hand,
                TextAlign = ContentAlignment.MiddleCenter
            };
            btnRegistration.FlatAppearance.BorderSize = 0;
            btnRegistration.Click += (s, e) => {
                RegistrationForm registrationForm = new RegistrationForm(currentUserId, currentUsername);
                registrationForm.ShowDialog();
            };

            // 医疗卡办理按钮
            Button btnMedicalCard = new Button
            {
                Text = $"{IconManager.Icons.Save}\r\n医疗卡办理",
                Size = new Size(200, 120),
                Location = new Point(400, 50),
                BackColor = Color.FromArgb(46, 204, 113),
                ForeColor = Color.White,
                Font = new Font("微软雅黑", 14, FontStyle.Bold),
                FlatStyle = FlatStyle.Flat,
                Cursor = Cursors.Hand,
                TextAlign = ContentAlignment.MiddleCenter
            };
            btnMedicalCard.FlatAppearance.BorderSize = 0;
            btnMedicalCard.Click += (s, e) => {
                MedicalCardForm medicalCardForm = new MedicalCardForm(currentUserId, currentRealName);
                medicalCardForm.ShowDialog();
            };

            // 医疗卡充值按钮
            Button btnCardRecharge = new Button
            {
                Text = $"{IconManager.Icons.Plus}\r\n医疗卡充值",
                Size = new Size(200, 120),
                Location = new Point(100, 200),
                BackColor = Color.FromArgb(155, 89, 182),
                ForeColor = Color.White,
                Font = new Font("微软雅黑", 14, FontStyle.Bold),
                FlatStyle = FlatStyle.Flat,
                Cursor = Cursors.Hand,
                TextAlign = ContentAlignment.MiddleCenter
            };
            btnCardRecharge.FlatAppearance.BorderSize = 0;
            btnCardRecharge.Click += (s, e) => {
                // 简单的输入对话框
                using (Form inputForm = new Form())
                {
                    inputForm.Text = "医疗卡充值";
                    inputForm.Size = new Size(350, 150);
                    inputForm.StartPosition = FormStartPosition.CenterParent;
                    inputForm.FormBorderStyle = FormBorderStyle.FixedDialog;
                    inputForm.MaximizeBox = false;
                    inputForm.MinimizeBox = false;
                    
                    Label lblPrompt = new Label() { Text = "请输入就诊卡号:", Location = new Point(20, 20), Size = new Size(100, 25) };
                    TextBox txtCardNo = new TextBox() { Location = new Point(130, 15), Size = new Size(150, 25) };
                    Button btnOK = new Button() { Text = "确定", Location = new Point(130, 60), Size = new Size(75, 25) };
                    Button btnCancel = new Button() { Text = "取消", Location = new Point(215, 60), Size = new Size(75, 25) };
                    
                    btnOK.Click += (sender, args) => { inputForm.DialogResult = DialogResult.OK; inputForm.Close(); };
                    btnCancel.Click += (sender, args) => { inputForm.DialogResult = DialogResult.Cancel; inputForm.Close(); };
                    
                    inputForm.Controls.AddRange(new Control[] { lblPrompt, txtCardNo, btnOK, btnCancel });
                    
                    if (inputForm.ShowDialog() == DialogResult.OK && !string.IsNullOrEmpty(txtCardNo.Text))
                    {
                        RechargeForm rechargeForm = new RechargeForm(txtCardNo.Text, currentUserId, currentRealName);
                        rechargeForm.ShowDialog();
                    }
                }
            };

            // 添加说明文字
            Label lblDescription = new Label
            {
                Text = "点击上方按钮进入相应功能模块",
                Font = new Font("微软雅黑", 12),
                ForeColor = Color.Gray,
                Location = new Point(200, 200),
                AutoSize = true
            };

            buttonContainer.Controls.Add(btnRegistration);
            buttonContainer.Controls.Add(btnMedicalCard);
            buttonContainer.Controls.Add(btnCardRecharge);
            buttonContainer.Controls.Add(lblDescription);

            outpatientPanel.Controls.Add(lblTitle);
            outpatientPanel.Controls.Add(buttonContainer);
            pnlContent.Controls.Add(outpatientPanel);
        }
    }
} 